package pe.gob.foncodes.ssa.bs.seguridad.domain;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import pe.gob.foncodes.ssa.bs.common.domain.EntidadBase;

/**
 *
 * @author Gcarlos
 */
@Entity
@Table(name = "MODULO", catalog = "", schema = "SSA")
@NamedQueries({
    @NamedQuery(name = "Modulo.findAll", query = "SELECT m FROM Modulo m"),
    @NamedQuery(name = "Modulo.findByTxtModulo", query = "SELECT m FROM Modulo m WHERE UPPER(m.txtModulo) LIKE ?1 ORDER BY m.txtModulo"),
    @NamedQuery(name = "Modulo.findByTxtModuloAndFlgActivo", query = "SELECT m FROM Modulo m WHERE UPPER(m.txtModulo) LIKE ?1 AND m.flgActivo = ?2 ORDER BY m.numOrden"),
    @NamedQuery(name = "Modulo.findOnlyNidModuloPadre", query = "SELECT m FROM Modulo m WHERE m.nidModuloPadre IS NULL ORDER BY m.txtModulo"),
    @NamedQuery(name = "Modulo.findOnlyNidModuloPadreAndFlgActivo", query = "SELECT m FROM Modulo m WHERE m.nidModuloPadre IS NULL AND m.flgActivo = ?1 ORDER BY m.numOrden"),
    @NamedQuery(name = "Modulo.findByNidModuloPadre", query = "SELECT m FROM Modulo m WHERE m.nidModuloPadre.id = ?1 ORDER BY m.numOrden"),
    @NamedQuery(name = "Modulo.findByNidModuloPadreAndFlgActivo", query = "SELECT m FROM Modulo m WHERE m.nidModuloPadre.id = ?1 AND m.flgActivo = ?2 ORDER BY m.numOrden"),
    @NamedQuery(name = "Modulo.findByFlgActivo", query = "SELECT m FROM Modulo m WHERE m.flgActivo = ?1 ORDER BY m.numOrden"),
    @NamedQuery(name = "Modulo.findByNidModuloFlgActivo", query = "SELECT m"
                                                                + " FROM Modulo m"
                                                                + " WHERE m.id = ?1"
                                                                + " AND m.flgActivo = ?2"),
    @NamedQuery(name = "Modulo.findByNidModulo", query = "SELECT m"
                                                                + " FROM Modulo m"
                                                                + " WHERE m.id = ?1")
})
public class Modulo extends EntidadBase implements Serializable {

    private static final long serialVersionUID = 1L;
    private String txtModulo;
    private String txtRutaInstalacion;
    private String txtRutaEjecucion;
    private String txtProposito;
    private String txtVersion;
    private String flgActivo;
    private String txtObservacion;
    private List<Modulo> moduloList;
    private Modulo nidModuloPadre;
    private String tipModulo;
    private List<Opcion> opcionList;
    private List<Perfil> perfilList;
    private List<ControlAcceso> controlAccesoList;
    private List<ConfiguracionModulo> configuracionModuloList;
    private String txtAbreviatura;
    private Integer numOrden;
    
    public Modulo() {
    }

    @Id
    @Basic(optional = false)
    @NotNull
    @SequenceGenerator(schema="SSA", name="SQ_MODULO",sequenceName="SSA.SQ_MODULO", allocationSize=1)
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SQ_MODULO")
    @Column(name = "NID_MODULO", nullable = false, precision = 0, scale = -127)
    @Override
    public Long getId() {
        return super.getId();
    }
    
    @Column(name = "NID_CONTROL_ACCESO_WEB", precision = 0, scale = -127)
    @Override
    public Long getNIdCtrlAccesoWeb() {
        return super.getNIdCtrlAccesoWeb();
    }
    
    @Basic(optional = false)
    @NotNull
    @Column(name = "TXT_MODULO", nullable = false, length = 250)
    public String getTxtModulo() {
        return txtModulo;
    }

    public void setTxtModulo(String txtModulo) {
        this.txtModulo = txtModulo;
    }

    @Column(name = "TXT_RUTA_INSTALACION", length = 250)
    public String getTxtRutaInstalacion() {
        return txtRutaInstalacion;
    }

    public void setTxtRutaInstalacion(String txtRutaInstalacion) {
        this.txtRutaInstalacion = txtRutaInstalacion;
    }

    @Column(name = "TXT_RUTA_EJECUCION", length = 250)
    public String getTxtRutaEjecucion() {
        return txtRutaEjecucion;
    }

    public void setTxtRutaEjecucion(String txtRutaEjecucion) {
        this.txtRutaEjecucion = txtRutaEjecucion;
    }

    @Column(name = "TXT_PROPOSITO", length = 250)
    public String getTxtProposito() {
        return txtProposito;
    }

    public void setTxtProposito(String txtProposito) {
        this.txtProposito = txtProposito;
    }

    @Column(name = "TXT_VERSION", length = 250)
    public String getTxtVersion() {
        return txtVersion;
    }

    public void setTxtVersion(String txtVersion) {
        this.txtVersion = txtVersion;
    }

    @Basic(optional = false)
    @NotNull
    @Column(name = "FLG_ACTIVO", nullable = false)
    public String getFlgActivo() {
        return flgActivo;
    }

    public void setFlgActivo(String flgActivo) {
        this.flgActivo = flgActivo;
    }

    @Column(name = "TXT_OBSERVACION", length = 250)
    public String getTxtObservacion() {
        return txtObservacion;
    }

    public void setTxtObservacion(String txtObservacion) {
        this.txtObservacion = txtObservacion;
    }

    @Column(name = "TIP_MODULO", nullable = false)
    public String getTipModulo() {
        return tipModulo;
    }

    public void setTipModulo(String tipModulo) {
        this.tipModulo = tipModulo;
    }

    @Column(name = "NUM_ORDEN")
    public Integer getNumOrden() {
        return numOrden;
    }

    public void setNumOrden(Integer numOrden) {
        this.numOrden = numOrden;
    }
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "nidModuloPadre")
    public List<Modulo> getModuloList() {
        return moduloList;
    }

    public void setModuloList(List<Modulo> moduloList) {
        this.moduloList = moduloList;
    }

    @JoinColumn(name = "NID_MODULO_PADRE", referencedColumnName = "NID_MODULO")
    @ManyToOne
    public Modulo getNidModuloPadre() {
        return nidModuloPadre;
    }

    public void setNidModuloPadre(Modulo nidModuloPadre) {
        this.nidModuloPadre = nidModuloPadre;
    }

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "nidModulo")
    public List<Opcion> getOpcionList() {
        return opcionList;
    }

    public void setOpcionList(List<Opcion> opcionList) {
        this.opcionList = opcionList;
    }

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "nidModulo")
    public List<Perfil> getPerfilList() {
        return perfilList;
    }

    public void setPerfilList(List<Perfil> perfilList) {
        this.perfilList = perfilList;
    }

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "nidModulo")
    public List<ControlAcceso> getControlAccesoList() {
        return controlAccesoList;
    }

    public void setControlAccesoList(List<ControlAcceso> controlAccesoList) {
        this.controlAccesoList = controlAccesoList;
    }

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "nidModulo")
    public List<ConfiguracionModulo> getConfiguracionModuloList() {
        return configuracionModuloList;
    }

    public void setConfiguracionModuloList(List<ConfiguracionModulo> configuracionModuloList) {
        this.configuracionModuloList = configuracionModuloList;
    }
    
    @Column(name = "TXT_ABREVIATURA", length = 50)
    public String getTxtAbreviatura() {
        return txtAbreviatura;
    }

    public void setTxtAbreviatura(String txtAbreviatura) {
        this.txtAbreviatura = txtAbreviatura;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (getId() != null ? getId().hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Modulo)) {
            return false;
        }
        Modulo other = (Modulo) object;
        if ((this.getId() == null && other.getId() != null) || (this.getId() != null && !this.getId().equals(other.getId()))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return getTxtModulo();
    }
}
